import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../config/app_colors.dart';
//JoyEmptyWidget
class JoyEmptyWidget extends StatefulWidget{

  final String messageError;
  final bool isNetError;
  final String errorImagePath;
  final String? btnTitle;
  final bool? isShowBtn;
  final Function tapOnCallBack;
  const JoyEmptyWidget({
    required this.messageError,
    this.isShowBtn = true,
    required this.isNetError,
    required this.errorImagePath,
    this.btnTitle = "No Data",
    required this.tapOnCallBack
  });


  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return JoyEmptyWidgetState();
  }

}
class JoyEmptyWidgetState extends State<JoyEmptyWidget>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return showEmptyOrder();
  }

  Widget showEmptyOrder(){
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 32.w),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          // 插画容器
          Container(
            width: 120.w,
            height: 120.w,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  AppColors.primary.withOpacity(0.1),
                  AppColors.primary.withOpacity(0.05),
                ],
              ),
              borderRadius: BorderRadius.circular(60.r),
            ),
            child: widget.errorImagePath.isNotEmpty 
                ? ClipRRect(
                    borderRadius: BorderRadius.circular(60.r),
                    child: Image.asset(
                      widget.errorImagePath,
                      fit: BoxFit.cover,
                    ),
                  )
                : Icon(
                    widget.isNetError ? Icons.wifi_off_rounded : Icons.search_off_rounded,
                    size: 60.sp,
                    color: AppColors.primary.withOpacity(0.6),
                  ),
          ),
          SizedBox(height: 32.h),
          Text(
            widget.isNetError ? 'Network Connection Failed' : 'No Data',
            style: TextStyle(
              fontSize: 20.sp,
              fontWeight: FontWeight.bold,
              color: AppColors.textPrimary,
            ),
          ),
          SizedBox(height: 12.h),
          Text(
            widget.messageError.isNotEmpty ? widget.messageError : 
            (widget.isNetError ? 'Please check your network connection and try again' : 'Try searching with different keywords'),
            textAlign: TextAlign.center,
            style: TextStyle(
              fontSize: 16.sp,
              color: AppColors.textSecondary,
              height: 1.5,
            ),
          ),
          SizedBox(height: 32.h),
          if (widget.isShowBtn ?? true) submitButton(context),
        ],
      ),
    );
  }

  Widget submitButton(BuildContext context){
    String btnTitleStr = widget.isNetError ? "Reload" : "Refresh";
    
    return GestureDetector(
      onTap: () => widget.tapOnCallBack(),
      child: Container(
        height: 56.h,
        width: double.infinity,
        margin: EdgeInsets.symmetric(horizontal: 32.w),
        decoration: BoxDecoration(
          gradient: LinearGradient(
            colors: [
              AppColors.primary,
              AppColors.primary,
            ],
          ),
          borderRadius: BorderRadius.circular(16.r),
          boxShadow: [
            BoxShadow(
              color: AppColors.primary.withOpacity(0.3),
              blurRadius: 12,
              offset: Offset(0, 4),
            ),
          ],
        ),
        child: Center(
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Icon(
                widget.isNetError ? Icons.refresh : Icons.search,
                color: Colors.white,
                size: 20.sp,
              ),
              SizedBox(width: 8.w),
              Text(
                btnTitleStr,
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.w600,
                  fontSize: 16.sp,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }


}
